﻿using System.Linq;
using System.Web.Mvc;
using Sharp.Platform.Mvc.Route;

namespace Sharp.Platform.Mvc.Extensions
{
    public static class AreaRegistrationContextExtensions
    {
        public static DomainRoute MapSaasRoute(this AreaRegistrationContext context, string name, string url,
            object defaults)
        {
            return MapSaasRoute(context, name, url, defaults, null, null);
        }

        public static DomainRoute MapSaasRoute(this AreaRegistrationContext context, string name, string url,
            object defaults, string[] namespaces)
        {
            return MapSaasRoute(context, name, url, defaults, null, namespaces);
        }
        public static DomainRoute MapSaasRoute(this AreaRegistrationContext context, string name, string url,
            object defaults, object constraints, string[] namespaces)
        {
            if (namespaces == null && context.Namespaces != null)
            {
                namespaces = context.Namespaces.ToArray();
            }
            var route = context.Routes.MapSaasRoute(name, url, defaults, constraints, namespaces);
            route.DataTokens["area"] = context.AreaName;
            bool flag = namespaces == null || namespaces.Length == 0;
            route.DataTokens["UseNamespaceFallback"] = flag;

            return route;
        }
    }
}
